import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {Card} from 'antd';
import routes from './routes';
import {Route, Switch} from 'react-router-dom';
import Breadcrumb from 'Shell/components/Breadcrumb';
import QueryPanel from './QueryPanel';
import TablePanel from './TablePanel';
import DetailPanel from './DetailPanel';
import NewPanel from './PageAdd/NewPanel';
import ApprovePanel from './ApprovePanel';
import NoMatchRoute from '../common/NoMatchRoute';
import HistoryQueryPanel from './HistoryQuery/HistoryQueryPanel';
import HistoryTablePanel from './HistoryQuery/HistoryTablePanel';
import HistoryDetailPanel from './HistoryQuery/HistoryDetailPanel';
import Return from '../common/Return';
import {formatMessage, injectIntl} from './intl';
class App extends PureComponent {
    componentDidMount() {
        this.props.queryInitDate();
    }
    render() {
        return (
            <div>
                <Route render={props => <Breadcrumb location={props.location}/>}/>
                <div className="page-main">
                    <Switch>
                        <Route path={routes.query.url()} exact render={() =>
                            <div>
                                <Card title={formatMessage({
                                    id: 'app.card.title',
                                    defaultMessage: '查询条件'
                                })}><QueryPanel /></Card>
                                <Card><TablePanel /></Card>
                            </div>}/>
                        <Route exact path={routes.add.url()} render={p => <NewPanel history={p.history}/>}/>
                        <Route exact path={routes.update.url()} render={p => <NewPanel id={p.match.params.id} history={p.history}/>}/>
                        <Route exact path={routes.approve.url()} render={p =>
                            <ApprovePanel id={p.match.params.id} page={'approve'} history={p.history}/>}/>
                        <Route exact path={routes.adjust.url()} render={p =>
                            <ApprovePanel id={p.match.params.id} page={'adjust'} history={p.history}/>}/>
                        <Route exact path={routes.detail.url()} render={p => <DetailPanel id={p.match.params.id} history={p.history}/>}/>
                        <Route exact path={routes.historyQuery.url()} render={props => (
                            <div>
                                <Card>
                                    <HistoryQueryPanel history={props.history}/>
                                </Card>
                                <Card>
                                    <HistoryTablePanel/>
                                </Card>
                                <div className="page-toolbar">
                                    <Return
                                        onConfirm={() => props.history.push(routes.query.url())} />
                                </div>
                            </div>
                        )}/>
                        <Route exact path={routes.historyDetail.url()} render={props =>
                            <HistoryDetailPanel id={props.match.params.id} history={props.history} />} />
                        <NoMatchRoute link={routes.query.url()} />
                    </Switch>
                </div>
            </div>
        );
    }
}

App.propTypes = {
    queryInitDate: PropTypes.func
};

import {connect} from 'react-redux';
import * as actions from './actions';

const mapDispatchToProps = dispatch => ({
    queryInitDate: () => {
        dispatch(actions.getInitData());
    }
});

export default connect(null, mapDispatchToProps)(injectIntl(App));
